<template>
  <div>
    <!-- 查询参数及按钮部分 -->
    <div class="filter-container">
      <el-dialog
        v-dialogDrag
        :close-on-click-modal="false"
        :title="dialogStatus"
        :visible.sync="dialogEditFormVisible"
        style="padding: 0px"
        width="60%"
      >
        <el-form
          ref="dataForm"
          class="dialog-Backgroundcolor"
          :model="listQuery"
          label-position="right"
          label-width="120px"
        >
          <el-row>
            <el-row style="margin-left: -30px">
              <el-col :span="12">
                <el-form-item label="姓名：">
                  <el-input v-model="formData.personName" type="text"  style="width: 100%;text-align: left" maxlength="30"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="身份证号码：">
                  <el-input v-model="formData.idenNo"  type="text" align="left" style="width: 100%"  maxlength="18"/>
                </el-form-item>
              </el-col>
              
            </el-row>
            <div style="float:right">
            <el-button
              type="primary"
              style="margin-left:10px;"
              @click="clearHandleFilter"
            >
              清除
            </el-button>
            <el-button
              type="primary"
              style="margin-left:10px;"
              @click="handleFilter"
            >
              查询
            </el-button>
            </div>
          </el-row>
        </el-form>
      </el-dialog>
    </div>
    <el-row>
      <el-col :span="4">
        <el-select
          v-model="formData.salaryType"
          class="filter-item"
          placeholder="工资类型"
          @change="handleFilter"
        >
          <el-option label="全部工资类型" value="" />
          <el-option
            v-for="item in salaryTypes"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          />
        </el-select>
      </el-col>
    </el-row>
    <el-row style="margin-top: 10px">
      <el-col :span="24">
        <div>单位名称：{{ unitName }}</div>
      </el-col>
    </el-row>
    <!-- 表格部分 -->
    <vxe-table
      ref="singalTable"
      v-loading="listLoading"
      border="inner"
      :data="list"
      show-overflow
      show-header-overflow
      show-footer-overflow
      :scroll-x="{enabled: true, gt: 100, oSize: 100}"
      :scroll-y="{enabled: true, gt: 100, oSize: 100}"
      :sort-config="{trigger: 'cell', orders: ['desc', 'asc', null]}"
      show-footer
      :footer-method="footerMethod"
      row-id="personId"
      fit
      :height="tableHeight"
      class="my-test"
      :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
    >
      <template slot="empty">
        <tableEmpty />
      </template>
      
      <vxe-table-column label="" min-width="50" fixed="left">
        <template v-slot:header>
          <vxe-checkbox
            v-model="checkAll"
            :indeterminate="indeterminate"
            @change="handleCheckAll"
          />
        </template>
        <template v-slot="scope">
          <vxe-checkbox
            v-model="scope.row.check"
            @change="handleCheck"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column title="序号" type="seq"  min-width="50" fixed="left" ></vxe-table-column>
      <vxe-table-column width="30" fixed="left">
        <template slot-scope="{ row }">
          <i v-if="row.existsFile === 1" class="el-icon-paperclip file-logo" />
        </template>
      </vxe-table-column>
      <vxe-table-column
        title="姓名"
        min-width="100"
        field="personName"
        fixed="left"
        sortable
      >
        <template slot-scope="{ row }">
            <span >{{
              row.personName
            }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column
        title="身份证号"
        min-width="200"
        field="idenNo"
        fixed="left"
        sortable
      >
        <template slot-scope="{ row }">
          <span >{{
            row.idenNo
          }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column
        title="银行"
        min-width="100"
        field="salaCardBank"
        sortable
      >
        <template slot-scope="{ row }">
          <span >{{
            row.salaCardBank |bankFilter(that)
          }}</span>
        </template>
      </vxe-table-column> 
      <vxe-table-column
        title="银行卡号"
        min-width="200"
        field="salaCardNo"
        sortable
      >
        <template slot-scope="{ row }">
          <span >{{
            row.salaCardNo
          }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column
        title="工资类型"
        min-width="200"
        field="meritPayCode"
        sortable
      >
      <template slot-scope="{ row }">
          <span >{{
            row.meritPayCode |meritPayCodeFilter(that)
          }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column
        title="发放比例"
        min-width="100"
        field="percent"
      >
        <template slot-scope="{ row }">
          <span >{{
            row.percent |percentfilter(that)
          }}</span>
        </template>
      </vxe-table-column>        
      <vxe-table-column v-for="item in columnNames" :field="item.split('_')[0]" :key="item" :title="item.split('_')[0] | salaryNameFilter(that)" align="right" min-width="150">
        <template slot-scope="{ row }">
          <!--判断当前行是否处于编辑状态，并且判断该字段是否是计算值-->
          <div>
            <vxe-input
              v-if="row.isOperate && item.split('_')[1] !== 'compute'"
              v-model="row['input' + item.split('_')[0]]"
              placeholder=""
              type="float"
              align="right"
              min="0"
              max="99999999"
              clearable
              @keyup.enter.native="nextInput($event)"
            />
            <span v-if="row.isOperate && item.split('_')[1] === 'compute'">{{
              Number(row["input" + item.split("_")[0]])
                .toFixed(2)
                .replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
            }}</span>
            <!--获取不带后缀的字段名-->
            <span v-if="!row.isOperate">{{
              Number(row[item.split("_")[0]])
                .toFixed(2)
                .replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
            }}</span>
          </div>
        </template>
      </vxe-table-column>
    </vxe-table>
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      title="导入"
      :visible.sync="dialogImportFormVisible"
      width="29%"
    >
      <el-upload
        class="upload-demo"
        drag
        style="padding-left: 2px"
        action="#"
        list-type="multipart/form-data"
        accept=".xls,.xlsx"
        :show-file-list="false"
        :http-request="uploadExcel"
        v-if="!importLoading"
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text" >将文件拖到此处，或<em>点击上传</em></div>
        <div slot="tip" class="el-upload__tip" />
      </el-upload>
      <span v-if="importLoading">正在处理，请稍等...</span>
    </el-dialog>
    
    <!--待增加人员页面-->
    <el-dialog
      v-dialogDrag
      title="待增加人员"
      :visible.sync="notAddPersonVisible"
      width="50%"
      max-height="500px"
    >
      <el-form
        ref="addPerson"
        :model="notAddfomrData"
        label-position="right"
        label-width="500px"
        size="small"
      >
      <el-row>
        <el-table
      ref="notAddPersonTable"
      v-loading="notAddPersonlistLoading"
      :data="notAddPerson"
      :stripe="true"
      fit
      highlight-current-row
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
    >
      <template slot="empty">
        <tableEmpty />
      </template>
      <el-table-column
        type="selection"
        width="55"
        align="center"
      />
      <el-table-column
        type="index"
        align="center"
        width="55"
        label="序号"
      />
      <el-table-column
        label="姓名"
        min-width="100"
        prop="personName"
        sortable
      />
      <el-table-column
        label="身份证号"
        min-width="200"
        prop="idenNo"
        sortable
      />
      <el-table-column
        label="银行"
        min-width="100"
        prop="salaCardBank"
        sortable
      >
        <template slot-scope="{ row }">
          <span >{{
            row.salaCardBank |bankFilter(that)
          }}</span>
        </template>
      </el-table-column> 
      <el-table-column
        label="银行卡号"
        min-width="200"
        prop="salaCardNo"
        sortable
      />
      <el-table-column
        label="发放比例"
        min-width="100"
        prop="percent"
      >
        <template slot-scope="{ row }">
          <span >{{
            row.percent |percentfilter(that)
          }}</span>
        </template>
      </el-table-column>  
        </el-table>
        
      </el-row>
    <el-row>
     <el-button
              type="primary"
              style="float: center"
              @click="subAddPerosn"
              :loading="subAddPerosnLoading"
            >
              增加所选人员
            </el-button>
    </el-row>
      </el-form>
     
    </el-dialog>
    <el-dialog  v-dialogDrag  
      title="审核说明"
      :visible.sync="auditFormVisible"
      width="30%"
      max-height="500px"
    >
      <el-form
        ref="auditForm"
        :model="auditFormData"
        label-position="right"
        label-width="120px"
        size="small"
      >
        <el-row>
          <el-col>
            <el-input
              v-model="auditFormData.auditExplain"
              type="textarea"
              :rows="4"
              maxlength="100"
              show-word-limit
            />
          </el-col>
        </el-row>
        <el-row>
          <el-col
            :span="16"
            style="text-align: right; margin-top:5%"
          >
            <el-button
              type="primary"
              :loading="saveExplainLoading"
              @click="saveExplain"
            >
              确定
            </el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <pagination
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
    <Enclosure ref="enc" :middle-table-code="2" />
    <PersonSalaryInfo ref="personSalaryInfo" />
    <ApprovalProcess ref="app" />
    
    <uploadLoadImport v-if="uploadLoadImportVisible" ref="uploadLoadImport" :guid="this.importGuid" :Executing="this.Executing" @close="uploadLoadImportVisibleClose"/>
  </div>
</template>
<script>
import {
  queryColumnName,
  queryUnitSalaryReportPage,
  querySalaryNameDict,
  submitData,
  outPutSalaryReportList,
  ImportAsync,
  deletePerson,
  getNotAddPerosn,
  addThirteenMonth,
  getThirteenAgencyWorkStatus
} from "@/api/thirteen/unitSalaryReport"
import { doWorkFlow, rejectWorkFlow ,backWorkFlow } from "@/api/thirteen/workFlow"
import { getSalaryType, getConfigCtrlByTypeMof, getIsLeafIds,getAgencyBank  } from "@/api/baseInfo"
import Pagination from "@/components/Pagination" // secondary package based on el-pagination
import tableEmpty from "@/components/table/empty"
import Enclosure from "@/components/Enclosure"
import PersonSalaryInfo from "@/components/personSalaryInfo/personSalaryInfo"
import ApprovalProcess from "@/components/ApprovalProcess/ApprovalProcessThirteen"
import uploadLoadImport from './uploadLoadImport'
export default {
  name: "UnitSalaryReportChildren",
  components: {
    ApprovalProcess,
    Pagination,
    tableEmpty,
    Enclosure,
    PersonSalaryInfo,
    uploadLoadImport
  },
  filters: {
    meritPayCodeFilter(type, that){
       const meritPayCodes = that.salaryTypes
        for (const item in meritPayCodes) {
          if (meritPayCodes[item].code === type) {
           return meritPayCodes[item].name
         }
      }
    },
      //银行
    bankFilter(type, that){
      const banks = that.allBankLists
      for (const item in banks) {
        if (banks[item].code === type) {
          return banks[item].name
        }
      }
    },
    // 工资项滤器
    salaryNameFilter(value, that) {
      const salaryNames = that.salaryNames;
      for (const item of salaryNames) {
        if (item.value === value) {
          return item.key;
        }
      }
    },
    percentfilter(value, that){
      if(value){
        return value*100+'%'
      }
    }
  },
  props: ["tabPane", "treeData"],
  data() {
    return {
      countnum: 0,
      agencyLists: [],
      number: 1,
      tableHeight: null,
      dialogStatus: "",
      dialogEditFormVisible: false,
      dialogImportFormVisible: false,
      uploadLoadImportVisible: false,
      importGuid:'',
      Executing:'',
      count: 0,
      upload_load:false,
      formStatus: "",
      configCtrl: "1",
      that: this,
      reallySendSalarySum: "0.00",
      workSalarySum: "0.00",
      retireSalarySum: "0.00",
      personTotal: "0",
      workTotal: "0",
      retireTotal: "0",
      unitMinusTotal: "0",
      unitPlusTotal: "0",
      retireMinusTotal: "0",
      workMinusTotal: "0",
      retirePlusTotal: "0",
      workPlusTotal: "0",
      openenclosure: true,
      accordion: false,
      isLeafIds: [],
      list: [],
      submitList: [],
      submitPersonIds: [],
      salaryTypes: [],
      allBankLists: [],
      total: 0,
      listLoading: false,
      notAddPersonlistLoading: false,
      subAddPerosnLoading: false,
      importLoading: false,
      listTree: null,
      defaultExpandedKey: [],
      clearable: true,
      treeQuery: '',
      firstAuthAgencyData: {},
      personnelCode: '',
      defaultProp: {
        id: "id",
        children: "children",
        label: "label",
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
      listQuery: {
        page: 1,
        limit: 500,
        flag: 'all',
        menuId: this.$router.currentRoute.meta.menuid,
        menuName:this.$router.currentRoute.meta.menuname
      },
      formData: {
        state: "", // 人员类别
        idenNo: "", // 身份证号码
        personName: "", // 姓名
        salaryType: "", //人员类型
        salaryColum: "",
        salaryColumMin: "",
        salaryColumMax: "",
        id: "",
        state: "",
        agencyCode: this.$store.getters.userInfo.agencyCode,
        agencyName: "",
        agencyId: "",
        deptId: "",
        deptName: "",
        idenNo: "",
        personnelCode: ''
      },
      auditFormData: {
        auditExplain: ''
      },
      columnNames: [], // 动态表头
      salaryNames: [],
      agencyVerList: [],
      unitName: "预算单位",
      agencyName: "",
      agencyId: null,
      menuid: this.$router.currentRoute.meta.menuid,
      menuName:this.$router.currentRoute.meta.menuname,
      isTodoOrBack: 0,
      bizKey: '',
      isSalarySubmit:'',
      checkAll: false,
      indeterminate: false,
      checkList: [],
      notAddPerson: [],
      changeList: {},
      inputList: {}, // 缓存最后一次输入正确的值，id{id}_inputs1 大括号内的id恢替换成id的数值
      notAddPersonVisible: false,
      auditFormVisible: false,
      saveExplainLoading:false,
      notAddfomrData:{},
      submitablenum: 0
    };
  },
  watch: {
    treeQuery(val) {
      this.$refs.tree.filter(val)
    },
    submitList: {
      immediate: true,
      deep: true,
      handler(val) {
        this.calculate(val);
      },
    },
    // 表格的数据数组
    // list(val) {
    //   this.doLayout()
    // },
    treeData(val) {
      if (val && val.isleaf === "1") {
        this.unitName = val.label.split("-")[1];
        this.agencyId = val.id;
        this.handleTree(val);
      }
    },
  },
  mounted() {   
    this.getTbHeight();
  },
  beforeMount() {
    window.addEventListener("resize", this.getTbHeight);
  },
  created() {  
    this.listQuery.flag = this.tabPane
    if (this.treeData && this.treeData.isleaf === "1") {
      this.unitName = this.treeData.label.split("-")[1]
      this.agencyId = this.treeData.id
      
      this.initDict()
      this.getThirteenAgencyWorkStatus()
      this.handleFilter()
    }
    this.getFirstAuthAgencyData()
    this.getIsLeafIds()
  },
  methods: {
    getIsLeafIds(){
      getIsLeafIds().then(res =>{
        this.isLeafIds = res.data;
      })
    },
    getFirstAuthAgencyData() {
        this.$emit('getFirstAuthAgencyData', this.$store.getters.getFirstAuthAgencyData)
    },

    // 树查询过滤
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 选择树
    handleNodeClicks(data) {
      this.$emit('handleTreeQuery', data)
      // if (!Object.prototype.hasOwnProperty.call(data, 'children')) {
      // }
    },
    processnode() {
      this.$refs.app.getList(this.agencyId);
    },
    // 获取table高度的方法
    getTbHeight() {
      this.tableHeight = window.innerHeight - this.$refs.singalTable.$el.offsetTop-200;
    },
    /* 重新渲染table组件 */
    doLayout() {
      this.$nextTick(() => {
        this.$refs.singalTable.doLayout()
      })
    },
   
    // 查询
    query() {
      this.clearHandle();
      this.dialogStatus = "查询";
      this.dialogEditFormVisible = true;
    },
    calculate(submitList) {
      // 获取每一行的数据进行计算
      for (const submit of submitList) {
            let calc = 0;
            let percent=submit.percent
            for (let arg of this.salaryNames) {
              if (!arg.value.endsWith("_compute")&&arg.value !== "s1") {
                  calc +=
                    (submit["input" + arg.value] === "") |
                    (submit["input" + arg.value] === undefined)|
                    (submit["input" + arg.value] === null)
                    
                      ? 0
                      :  Number(submit["input" + arg.value], 2);
              } 
            }
            calc=calc*percent
            submit["inputs1"] = Number(
              this.$math.round(this.$math.evaluate(calc), 2)
            );
        
      }
    },
    querySalaryNameDict() {
      Object.assign(this.listQuery, this.formData);
      this.listQuery["agencyId"] = this.agencyId;
      // 查询工资项名称
      querySalaryNameDict(this.listQuery)
        .then((res) => {
          this.salaryNames = res.data;
        })
        .catch(() => {
          this.salaryNames = [];
        });
    },

    // 初始化字典
    initDict() {
      //获取工资类型
      getSalaryType().then((response) => {
        this.salaryTypes = Object.assign({}, response.data);
      });
      // 查询工资项名称
      querySalaryNameDict(this.listQuery)
        .then((res) => {
          this.salaryNames = res.data;
        })
        .catch(() => {
          this.salaryNames = [];
        });
  
    
      //获取是否上传附件做校验
      getConfigCtrlByTypeMof("fileVerify").then((response) => {
        this.configCtrl = response.data;
      });
      getAgencyBank().then(response => {
        this.agencyBankLists = response.data
        this.allBankLists = response.data
      })
    },

    getThirteenAgencyWorkStatus() {
      const params = {
                    agencyId: this.agencyId,
                    menuId: this.menuid,
                  };
      // 查询流程待办状态
      return getThirteenAgencyWorkStatus(params)
        .then((res) => {
          this.isTodoOrBack = res.data.status
          this.bizKey=res.data.bizKey
          this.isSalarySubmit=res.data.isSalarySubmit
        })
    },
  //新增人员方法
    addPerson(){
      if (this.isTodoOrBack === 1) {
        this.$message({
          message: "数据未在当前岗！不可操作",
          type: "warning",
          showClose: true,
          duration: 4000,
        })
        return
      }
          this.subAddPerosnLoading=false
          
          this.notAddPersonlistLoading=true
      this.listQuery["agencyId"] = this.agencyId;
      getNotAddPerosn(this.listQuery).then(res=>{
        this.notAddPerson=res.data
         this.notAddPersonlistLoading=false
        if(this.notAddPerson.length==0){
         this.notAddPersonVisible=false
         this.$message({
            message: "无可添加人员",
            type: "warning",
            showClose: true,
            duration: 4000,
          });
        return
        }
        this.notAddPersonVisible=true
      })
    },
    //增加十三月工资人员
    subAddPerosn(){
      this.subAddPerosnLoading=true
      const selection = this.$refs.notAddPersonTable.selection
      if (selection.length === 0) {
        this.$message({
            message: "请选择要添加的人员",
            type: "warning",
            showClose: true,
            duration: 4000,
          });
          this.subAddPerosnLoading=false
        return
      }
      addThirteenMonth(selection).then(res=>{
        this.$message({
                message: "增加人员成功",
                type: "success",
                showClose: true,
                duration: 4000,
              });
        this.notAddPersonVisible=false
        this.handleFilter()
      })
    },
//删除人员方法
    deletePerson(){
      const selection = this.checkList;
        if (selection.length === 0) {
          this.$message({
            message: "请选择数据",
            type: "warning",
            showClose: true,
            duration: 4000,
          });
          return;
        }
        let deletePersonNames=''
        let ids=[]
        selection.forEach(element => {
          deletePersonNames+=element.personName+" "
          ids.push(element.id)
        });
        
        this.$confirm('确定删除'+deletePersonNames+'吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
        }).then(() => {
            deletePerson(ids).then(re=>{
              this.$message({
                message: "删除人员成功",
                type: "success",
                showClose: true,
                duration: 4000,
              });
              this.handleFilter()
            })
        })
    },
    

    // 动态获取表头
    getColumnNames() {
      Object.assign(this.listQuery, this.formData);
      this.listQuery["agencyId"] = this.agencyId;
      queryColumnName(this.listQuery)
        .then((response) => {
          this.columnNames = response.data;
        })
        .catch(() => {
          this.columnNames = [];
        });
    },
    handleTree(data) {
      this.initDict();
      this.getThirteenAgencyWorkStatus();
      this.handleFilter();
    },
    // 查询
    handleFilter() {
      this.listQuery.page = 1;
      // this.listQuery.limit = 10
      this.getList();
      this.dialogEditFormVisible = false;
    },
    //清除查询信息
    clearHandleFilter(){
      this.formData.personName=''
      this.formData.idenNo=''
    },
    initData() {
      this.checkAll = false;
      this.indeterminate = false;
      this.listLoading = false;
      this.submitList = [];
      this.submitPersonIds = [];
      this.checkList = [];
      this.inputList = {};
    },

    // 获取数据
    getList() {
      this.listLoading = true;
      this.getColumnNames();
      Object.assign(this.listQuery, this.formData);
      this.listQuery["agencyId"] = this.agencyId;
      queryUnitSalaryReportPage(this.listQuery)
        .then((response) => {
          this.list = response.data.rows;
          for (const item of this.list) {
            this.$set(item, "check", false);
          }
          this.total = response.data.total;
          this.initData();
        })
        .catch(() => {
          this.list = [];
          this.total = 0;
          this.initData();
        });
    },
    // 编报，修改
    handleEdit() {
        const selection = this.checkList;
        if (selection.length === 0) {
          this.$message({
            message: "请选择数据",
            type: "warning",
            showClose: true,
            duration: 4000,
          });
          return;
        }
        //修改按钮为取消修改
        this.$emit("handleIsEdited")
        for (let name of this.columnNames) {
          name = name.split("_")[0];
          for (const item of selection) {
            let value = "";
            if (item[name] !== 0) {
              value = item[name];
            }
            this.$set(item, "input" + name, value);
          }
        }
        for (const item of selection) {
          if (!this.submitPersonIds.includes(item.personId)) {
            this.$set(item, "isOperate", true);
            this.$set(item, "columnNames", this.columnNames.join(","));
            this.submitPersonIds.push(item.personId);
            this.submitList.push(item);
          }
        }
        this.calculate(this.submitList);
    },
    // 保存
    handleSave() {
      const submitList = this.submitList;
      if (submitList.length === 0) {
        this.$message({
          message: "没有可保存的数据",
          type: "warning",
          showClose: true,
          duration: 4000,
        });
        this.$emit("handleSaveBtnLoading");
        return;
      }
      for (const submit of submitList) {
            for (let name of this.columnNames) {
              name = name.split("_")[0];
              submit[name] = submit["input" + name];
            }
      }
      submitData(submitList)
          .then((response) => {
              if (response.data === 0) {
                this.$message({
                  showClose: true,
                  message: "保存成功！",
                  type: "success",
                  duration: 4000,
                  // onClose: this.appendixOpen //如果存在未上传附件的人员，则打开附件管理让其上传附件
                });
              } else {
                this.$message({
                  message: "保存成功",
                  type: "success",
                  showClose: true,
                  duration: 4000,
                });
              }
              this.getList() ;
              //修改按钮为取消修改
              this.$emit("handleIsEdited")
              this.$emit("handleSaveBtnLoading");
            })
            .catch(() => {
              this.$emit("handleSaveBtnLoading");
            });
    },


    uploadClose() {
      this.upload_load = false
       this.$emit('handleSubmitBtnLoadings')
      // this.listQuery.agencySelected=''//批量生成完后清空选择值，再调查询方法，否则会报414
      // this.getMessage()
       this.handleFilter()
    },
    uploadLoadImportVisibleClose() {
      this.uploadLoadImportVisible = false
      this.getList()
    },


    // 送审
    handleSubmit() {
      if(this.total === 0){
        this.$message({
          message: "没有可送审的数据",
          type: "warning",
          showClose: true,
          duration: 4000,
        });
        this.$emit("handleSubmitBtnLoading");
        return;
      }
      if (this.isTodoOrBack === 1) {
        this.$message({
          message: "没有可送审的数据",
          type: "warning",
          showClose: true,
          duration: 4000,
        });
        this.$emit("handleSubmitBtnLoading");
        return;
      }

                const params = [{
                    bizKey: this.bizKey,
                    isSalarySubmit:this.isSalarySubmit
                  }];
                const data={agencyVerifyList:params,menuId:this.menuid,menuName:this.menuName,params:this.$route.meta.pageUrl}
                doWorkFlow(data)
                  .then((res) => {
                    this.$message({
                      message: "送审成功",
                      type: "success",
                      showClose: true,
                      duration: 4000,
                    });
                // 刷新数据
                      this.getList();
                      this.getThirteenAgencyWorkStatus()
                      this.$emit("handleSubmitBtnLoading");
                      this.$emit("handleSubmitBtnLoadings");
                    })
                    .catch(() => {
                        this.$emit("handleSubmitBtnLoading");
                    });
    },
    // 撤销送审
    handleRejectSubmit() {
      if (this.total === 0) {
        this.$message({
          message: "没有可操作的数据",
          type: "warning",
          showClose: true,
          duration: 4000,
        });
        this.$emit("handleRejectSubmitBtnLoading");
        return;
      }
        const params = [{ bizKey: this.bizKey,
                    isSalarySubmit:this.isSalarySubmit }]
        const data={agencyVerifyList:params,menuId:this.menuid,menuName:this.menuName,params:this.$route.meta.pageUrl}
        rejectWorkFlow(data)
            .then((res) => {
              this.$message({
                message: "撤销成功",
                type: "success",
                showClose: true,
                duration: 4000,
              });
              // 刷新数据
              this.getList();
              this.$emit("handleRejectSubmitBtnLoading");
            
        })
        .catch(() => {
          this.$emit("handleRejectSubmitBtnLoading");
        });

    },
     // 退回
    auditReject() {
      if (this.total === 0) {
        this.$message({
          message: "没有可操作的数据",
          type: "warning",
          showClose: true,
          duration: 4000,
        });
        this.$emit("handleReturnedBtnLoading");
        return;
      }
      this.auditFormData.auditExplain = ''
      this.auditFormVisible = true
    },
    // 统一保存
    saveExplain() {
      this.saveExplainLoading = true
      this.handleReturned()
    },
     // 退回
    handleReturned() {
      if (this.total === 0) {
        this.$message({
          message: "没有可操作的数据",
          type: "warning",
          showClose: true,
          duration: 4000,
        });
        this.$emit("handleReturnedBtnLoading");
        return;
      }
      if (this.auditFormData.auditExplain === '') {
        this.$message({
          message: "请填写退回原因！",
          type: "warning",
          showClose: true,
          duration: 4000,
        });
         this.saveExplainLoading = false
        return;
      }
        const params = [{ bizKey: this.bizKey,
                    isSalarySubmit:this.isSalarySubmit }]
        
        const data={agencyVerifyList:params,menuId:this.menuid,menuName:this.menuName,auditExplain : this.auditFormData.auditExplain,params:this.$route.meta.pageUrl}
        backWorkFlow(data)
            .then((res) => {
              this.$message({
                message: "退回成功",
                type: "success",
                showClose: true,
                duration: 4000,
              });
              // 刷新数据
            this.auditFormVisible = false
            this.saveExplainLoading = false
            this.getList();
            this.$emit("handleReturnedBtnLoading");
            
        })
        .catch(() => {
          this.$emit("handleReturnedBtnLoading");
        });

    },

    // 全选
    handleCheckAll(val) {
      const checked = val.checked;
      for (let i = 0; i < this.list.length; i++) {
        this.list[i].check = checked;
      }
      this.checkAll = true;
      this.indeterminate = false;
      this.checkList = [];
      if (checked) {
        for (const item of this.list) {
          if (item.check) {
            this.checkList.push(item);
          }
        }
      }
    },

    // 点击多选按钮
    handleCheck() {
      this.checkList = [];
      const totalCount = this.list.length - 1;
      let isCheckedCount = 0;
      this.list.forEach((item) => {
        if (item.check) {
          this.checkList.push(item);
          isCheckedCount++;
        }
      });
      this.checkAll = totalCount === isCheckedCount;
      this.indeterminate = isCheckedCount > 0 && isCheckedCount < totalCount;
    },
    // 附件方法
    appendixOpen() {
      const that = this;
      const selection = that.checkList;
       if(selection.length>0){
      const arr=[]
      for(let i=0;i<selection.length;i++){
          arr.push(selection[i].personName)
          }
      this.$confirm( "当前操作"+arr+ ' 提示!', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            center: true
          }).then(() => {
		that.openenclosure = true;
		const idList = [];
      selection.forEach((item) => {
        idList.push({ id: item.personId });
      });
      that.$refs.enc.appendixOpen(idList,that.openenclosure,undefined,this.agencyId)
       }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消上传'
          });
        });
     }else {
          that.openenclosure = false;
		  if (this.isTodoOrBack === 1) {
        that.openenclosure = false;
      }
          const idList = [];
      selection.forEach((item) => {
        idList.push({ id: item.personId });
      });
         that.$refs.enc.appendixOpen(idList,that.openenclosure,undefined,this.agencyId)
     }
    },
    // 查看详情
    viewInfo(currenRow) {
      const personId = currenRow.personId.replace("noRepeat", "");
      this.$refs.personSalaryInfo.viewInfo(personId, undefined, this.agencyId);
    },
    // 导出
    outPutFile() {
       if (this.isTodoOrBack === 1) {
        this.$message({
          message: "数据未在当前岗！不可操作",
          type: "warning",
          showClose: true,
          duration: 4000,
        })
        return
      }
      Object.assign(this.listQuery, this.formData);
      this.listQuery["agencyId"] = this.agencyId;
      outPutSalaryReportList(this.listQuery).then((response) => {
        const link = document.createElement("a");
        const objectUrl = URL.createObjectURL(response);
        link.href = objectUrl;
        link.download = "单位工资编报.xls";
        link.click();
        URL.revokeObjectURL(objectUrl);
      });
    },
    // 上传文件
    uploadExcel(item) {
      this.importLoading=true
      const fileObj = item.file;
      // FormData 对象
      const form = new FormData()
      // 文件对象
     
      form.append("file", fileObj)
      form.append("agencyId", this.agencyId)
      ImportAsync(form)
        .then((response) => {
          this.dialogImportFormVisible = false
          this.importGuid=response.data.guid
          this.Executing=response.data.Executing
          this.uploadLoadImportVisible = true
           this.importLoading=false
        })
    },
    // 导入
    importFile() {
      if (this.isTodoOrBack === 1) {
        this.$message({
          message: "当前单位数据已送审，不可导入！",
          type: "warning",
          showClose: true,
          duration: 4000,
        });
        return;
      }
      this.dialogImportFormVisible = true;
    },
    // 树点击
    handleNodeClick(data) {
      this.formData.deptId = data.id;
      this.formData.deptName = data.label;
      if (this.formData.deptName === "组织机构") {
        this.formData.deptId = "";
        this.formData.deptName = "";
      } else {
        this.$refs.selectReport.blur();
      }
    },
    // 清除下拉树选中
    clearHandle() {
      this.formData.deptName = "";
      this.formData.deptId = "";
      this.defaultExpandedKey = [];
    },
    
    nextInput(event) {
      const vElem = event.target;
      const inputArray = document.getElementsByClassName("vxe-input--inner");
      for (let index = 0; index < inputArray.length; index++) {
        if (vElem === inputArray[index]) {
          inputArray[index + 1].focus()
          return;
        }
      }
    },
    meanNum (list, field) {
      let count = 0
      list.forEach(item => {
        count += Number(item[field])
      })
       return count / list.length
    },
    sumNum (list, field) {
      let count = 0
      list.forEach(item => {
        count += Number(item[field])
        })
      return count
    },
    footerMethod ({ columns, data }) {
      
      const sums = []
      columns.forEach((column, columnIndex) => {
        if (columnIndex === 0) {
          sums.push('合计')
        } else {
          let sumCell = null
          if (columnIndex>8) {
             sumCell = this.sumNum(data, column.property)
            sumCell = Number(sumCell).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
          }else{
            sumCell=''
          }
          sums.push(sumCell)
        }
      })
              // 返回一个二维数组的表尾合计
      return [sums]
   }
    
  }
}
</script>
<style lang="scss">
.el-message-box {
    width:auto;
    overflow-y: scroll;
    vertical-align: middle;
    background-color: #FFFFFF;
    border-radius: 4px;
    border: 1px solid #e6ebf5;
    font-size: 18px;
    -webkit-box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
    box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
    text-align: left;
    overflow: hidden;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}
.el-message-box--center .el-message-box__message {
     max-width : 800px;
     max-height : 500px;
         overflow-y:auto
}
</style>
<style lang="scss" scoped>
.file-logo {
  color: #0b68ea;
  font-weight: 900;
  font-size: 18px;
}
.warn-font-color {
  color: red;
}

.el-table {
  .cell {
    .el-table__expand-icon {
      display: none;
    }

    .el-table__indent {
      padding-left: 0 !important;
    }

    .el-table__placeholder {
      display: none;
    }
  }
}

/** 文本框高度 **/
.el-input:not(.el-pagination__editor):not(.el-input--mini) {
  width: 130px;
  height: 40px !important;
}

//::v-deep深度作用选择器混用本地和全局样式
.el-input:not(.el-pagination__editor):not(.el-input--mini)
  .el-input__inner {
  height: 35px;
  text-align: right !important;
}
.agencyTree {
    .el-input {
      width: 100% !important;
      height: 40px !important;
      .el-input__inner{
        height: 35px;
      }
    }
}
</style>
